<template>
  <div id="user">
    <div class="usertop">
      <div class="ut_box">
        <div class="logo">
          <img :src="photo" alt v-if="photo" />
        </div>
        <div class="center">
          <div class="name">{{ nickName }}</div>
          <div class="zsid" v-if="phone">
            <span>{{ phone }}</span>
          </div>
        </div>
        <div class="vip_level_box">
          <div class="v0" v-if="vipLevel == 0">
            <span class="vip0"></span>免费版
          </div>
          <div class="v1" v-if="vipLevel == 1">
            <span class="vip1"></span>SVIP-企业版
          </div>
          <div class="v1" v-if="vipLevel == 5">
            <span class="vip1"></span>SVIP-个人版
          </div>
          <div class="v2" v-if="vipLevel == 2">
            <span class="vip2"></span>Puls会员-企业版
          </div>
          <div class="v3" v-if="vipLevel == 3">
            <span class="vip3"></span>体验版
          </div>
          <div class="v4" v-if="vipLevel == 4">
            <span class="vip4"></span>VIP-企业版
          </div>
        </div>
      </div>
      <!-- <div class="mybg tag-read" data-clipboard-text="https://dy.zsjx114.com/" @click="copyCode"> -->
        <div class="mybg tag-read">
          <template v-if="isShowBox">
            <template v-if="vipLevel">
              <p>您当前是<span>{{$levelName(vipLevel)}}</span><span v-if="$levelV(vipLevel)">{{'-'+$levelV(vipLevel)}}</span></p>
              <p v-if="vipLevel == '5' && autoVipType != '0'"><span>(连续包{{vipDuration == '12' ? '年' : vipDuration == '3' ? '季' : '月'}})</span></p>
              <p v-else><span>{{vipEndTime.split(' ')[0]}}</span>到期</p>
            </template>
            <template v-else>
              <p>您当前是免费版会员</p>
              <p>开通会员可享有更多服务</p>
            </template>
          </template>
        </div>
    </div>
    <div class="content">
      <div class="content_items">
        <router-link to="/myStar" tag="div" class="user_enter_item">
          <div class="uei_left">
            <i class="enter_icon collect"></i>
            <span>我的收藏</span>
          </div>
          <div class="uei_right">
            <i class="arrow"></i>
          </div>
        </router-link>
        <router-link to="/buyVip" tag="div" class="user_enter_item">
          <div class="uei_left">
            <i class="enter_icon buy"></i>
            <span>购买续费</span>
          </div>
          <div class="uei_right">
            <i class="arrow"></i>
          </div>
        </router-link>
        <router-link to="/cardBag" tag="div" class="user_enter_item">
          <div class="uei_left">
            <i class="enter_icon coupon"></i>
            <span>卡券包</span>
          </div>
          <div class="uei_right">
            <span class="ci_badge" v-if="$store.state.unreadMsg">{{$store.state.unreadMsg}}</span>
            <i class="arrow"></i>
          </div>
        </router-link>
        <router-link :to="{path:'/invitation',query:{'invitecode':invitecode}}" tag="div" class="user_enter_item" v-if="invitecode">
          <div class="uei_left">
            <i class="enter_icon share"></i>
            <span>邀好友送会员</span>
          </div>
          <div class="uei_right">
            <i class="arrow"></i>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
import Clipboard from 'clipboard';
import Vue from 'vue';
import { Toast } from 'vant';

Vue.use(Toast);
export default {
  props: {},
  data() {
    return {
      photo: '', //头像
      vipLevel: null, //判断vip
      phone: '',
      nickName: '',
      vipEndTime:'',  //会员到期时间
      isShowBox:false,
      autoVipType:'',
      invitecode:'',
    };
  },
  computed: {},
  created() {
    this.get_person();
    this.getInviterCode();
    // // 存储用户名称
    // this.nickName = localStorage.getItem('nickName')
    // //存储头像
    // this.photo = localStorage.getItem('photo')
    // console.log(this.photo + '   头像')
    // // 存储是否为vip状态
    // this.vipLevel = localStorage.getItem('vipLevel')
    // // 存储手机号phone
    // this.phone = localStorage.getItem('phone')
  },
  mounted() {},
  watch: {},
  methods: {
    getInviterCode(){
      this.$axios.get('/api/customer/GetInviterCode').then((res)=>{
        if(res && res.data.code == '0'){
          this.invitecode = res.data.data.invitecode;
        }
      });
    },
    get_person() {
      let that = this;
      this.$axios(
        {
          method: 'get',
          url: '/api/customer/getperson' //是否登录
        })
        .then(res => {
          //存储头像
          //  this.photo= localStorage.setItem('photo', response.data.data.headImgUrl)
          //   // 存储是否为vip状态
          //  this.vipLevel= localStorage.setItem('vipLevel', response.data.data.vipLevel)
          //   // 存储手机号phone
          //  this.phone= localStorage.setItem('phone', response.data.data.phone)
          //   // 存储用户名称
          //   this.nickName=localStorage.setItem('nickName', response.data.data.nickName)
          this.isShowBox = true;
          if (res.data.code == 0) {
            this.photo = res.data.data.headImgUrl;
            this.vipLevel = res.data.data.vipLevel;
            this.phone = res.data.data.phone;
            this.nickName = res.data.data.nickName;
            this.person_message = res.data.data;
            this.autoVipType = res.data.data.autoVipType;
            this.vipDuration = res.data.data.duration;

            localStorage.setItem('photo', res.data.data.headImgUrl);
            localStorage.setItem('vipLevel', res.data.data.vipLevel);
            localStorage.setItem('phone', res.data.data.phone);
            localStorage.setItem('nickName', res.data.data.nickName);
            localStorage.setItem('autoVipType', res.data.data.autoVipType);
            localStorage.setItem('vipDuration', res.data.data.duration);
            // 会员到期时间
            this.vipEndTime = res.data.data.vipEndTime1;
            if (res.data.data.vipLevel == '0') {
              localStorage.setItem('vipEndTime1', 0);
            } else {
              localStorage.setItem('vipEndTime1', res.data.data.vipEndTime1);
            }
          }
          // 走main.js的拦截器逻辑
          // if (res.data.code == 1006) {
          //   let viewer = window.navigator.userAgent.toLowerCase();
          //   // 微信浏览器打开
          //   if (viewer.match(/MicroMessenger/i) == 'micromessenger') {
          //     this.$router.push('/loginweixin');
          //   } else {
          //     // 外部浏览器
          //     this.$router.push('/login');
          //   }
          // }
        })
        .catch(error => {
          console.log(error);
        });
    },
    copyCode() {
      var clipboard = new Clipboard('.tag-read');
      clipboard.on('success', e => {
        Toast({ message: '复制成功', duration: 3000 });
        // 释放内存
        clipboard.destroy();
      });
      clipboard.on('error', e => {
        // 不支持复制
        //   console.log('该浏览器不支持自动复制')
        // 释放内存
        clipboard.destroy();
      });
    },
    // 退出
    logout() {
      localStorage.removeItem('user_id');
      localStorage.removeItem('phone');
      localStorage.removeItem('photo');
      localStorage.removeItem('nickName');
      localStorage.removeItem('vipLevel');
      location.href = '/';
    },
  },
  components: {}
};
</script>

<style scoped lang="less">
#user {
  overflow: hidden;
  background: #f1f1f1;
  min-height: 100vh;
  .usertop {
    position: relative;
    // margin-top: 0.133333rem;
    width: 100%;
    padding-top: 1.3rem;
    padding: 1.3rem .4rem 0;
    background: url(../../assets/three/bg09.png);
    background-size: 100% auto;
    box-sizing: border-box;
    .ut_box{
      display: flex;
      align-items: center;
    }
    .logo {
      flex-shrink: 0;
      margin-right: 0.36rem;
      width: 1.613333rem;
      height: 1.613333rem;
      border: solid 1px #e5e5e5;
      border-radius: 50%;
      overflow: hidden;
      background-color: #efefef;
      img {
        width: 1.613333rem;
        height: 1.613333rem;
        border-radius: 50%;
      }
    }
    .center {
      .name {
        font-size: 0.426667rem;
        font-weight: 600;
        color: #313246;
      }
      .zsid {
        display: flex;
        font-size: 0.346667rem;
        color: #313246;
        width: 4rem;
        margin-top: .16rem;
        align-items: center;
        position: relative;
      }
    }
    .vip_level_box {
      margin-left: auto;
      img {
        width: 1.866667rem;
        height: 0.626667rem;
      }
      .v1 {
        color: #737e9e;
      }
      .v2 {
        color: #ba8150;
      }
      .v3 {
        color: #936c33;
      }
      .v4 {
        color: #a67458;
      }
      &>div {
        position: relative;
        font-size: 0.32rem;
        // width: 2rem;
        padding: 0 .3rem 0 .4rem;
        height: 0.533333rem;
        line-height: 0.533333rem;
        text-align: center;
        border-radius: 0.266667rem;
        background-color: #ffffff;
        span {
          position: absolute;
          left: -0.366667rem;
          top: -0.08rem;
          width: 0.64rem;
          height: 0.64rem;
          line-height: 0.64rem;
          border-radius: 50%;
          box-shadow: inset 0px 0px 7px 0px rgba(49, 51, 71, 0.09);
          background: #fff url('../../assets/three/vip0.png') no-repeat center;
          color: #686a6e;
          background-size: 0.493333rem 0.36rem;
        }

        .vip1 {
          background: #fff url('../../assets/three/vip1.png') no-repeat center !important;
          background-size: 0.493333rem 0.36rem !important;
        }
        .vip2 {
          background: #fff url('../../assets/three/vip2.png') no-repeat center !important;
          background-size: 0.493333rem 0.36rem !important;
        }
        .vip3 {
          background: #fff url('../../assets/three/vip3.png') no-repeat center !important;
          background-size: 0.493333rem 0.36rem !important;
        }
        .vip4 {
          background: #fff url('../../assets/three/vip4.png') no-repeat center !important;
          background-size: 0.493333rem 0.36rem !important;
        }
      }
    }
    .mybg {
      height: 1.413333rem;
      background-image: url('../../assets/three/mybg_03.png');
      background-size: 100% 100%;
      box-sizing: border-box;
      padding-left: 1.2rem;
      font-size: 0;
      margin-top: .6rem;
      display: flex;
      justify-content: center;
      align-items: flex-start;
      flex-direction: column;
      
      P {
        font-size: 0.346667rem;
        color: #fddbbe;
        margin: .04rem 0;
        &:nth-child(1) {
          top: 0.333333rem;
          font-size: 0.346667rem;
        }
      }
      button {
        font-size: 0.346667rem;
        border: none;
        background: none;
        color: #fddbbe;
      }
      img {
        width: 9.2rem;
        height: 1.413333rem;
      }
    }
  }
  .content {
    padding: 0 .4rem;
    margin-top: 0.333333rem;
    .content_items{
      border: 1px solid #fff;
      background-color: #ffffff;
      padding: 0 .4rem;
      border-radius: 0.133333rem;
      .user_enter_item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 1.68rem;
        border-bottom: 1px solid #e5e5e5;
        &:last-child{
          border: none;
        }
        .uei_left{
          display: flex;
          align-items: center;
          .enter_icon{
            display: inline-block;
            width: .4rem;
            height: .4rem;
            margin-right: .2667rem;
            background-repeat: no-repeat;
            background-size: 100% 100%;
            &.collect{
              background-image: url(../../assets/img/user_star.png);
            }
            &.buy{
              background-image: url(../../assets/img/user_goumaivip.png);
            }
            &.coupon{
              background-image: url(../../assets/img/user_cardbag.png);
            }
            &.share{
              background-image: url(../../assets/img/user_share.png);
            }
          }
          span{
            font-size: .4rem;
            color: #222;
          }
        }
        .uei_right{
          display: flex;
          align-items: center;
          .arrow{
            display: inline-block;
            width: 0.173333rem;
            height: 0.306667rem;
            background-repeat: no-repeat;
            background-size: 100% 100%;
            background-image: url(../../assets/three/jt_03.png);
            margin-left: .2667rem;
          }
          .ci_badge{
            display: inline-block;
            box-sizing: border-box;
            min-width: .4933rem;
            padding: 0 .08rem;
            height: .4933rem;
            line-height: .4933rem;
            border-radius: .4933rem;
            background-color: #fd7f2c;
            color: #fff;
            font-size: .3467rem;
            text-align: center;
            font-style: normal;
          }
        }
      }
    }
  }
}
</style>
